package ch.zbw.sysventory.server.service.security.impl;

import java.math.BigInteger;
import java.security.MessageDigest;

import org.springframework.stereotype.Service;

import ch.zbw.sysventory.server.service.security.PasswordService;

@Service
public class PasswordServiceImpl implements PasswordService {

	@Override
	public String getMD5EncodedPassword(String password) throws Exception {
		MessageDigest messageDigest = MessageDigest.getInstance("MD5");
		messageDigest.update(password.getBytes(), 0, password.length());
		String hashedPass = new BigInteger(1, messageDigest.digest()).toString(16);
		if (hashedPass.length() < 32) {
			hashedPass = "0" + hashedPass;
		}
		return hashedPass;
	}

}
